<include file="header" />
<body>
    <div class="wraper" id="register">
        <div class="title text-center white">登录</div>
        <div class="main-register">
            <div class="information-box flex-between">
                <div class="iconfont icon-msnui-user blue">
                </div>
                <input type="text" class="flex-1 phone-input" id="tel"  name="tel" placeholder="请输入手机号码">
                <a href="javascript:void(0)" class="send font-12 text-center white" id="post">获取验证码</a>
            </div>
            <div class="information-box flex-between margin-t22">
                <div class="iconfont icon-suo blue">
                </div>
                <input type="text" class="flex-1 phone-input" name="token" id="token" placeholder="请输入验证码">
            </div>
            <a href="javascript:void(0)" class="text-center btn font-16 white"  id="reg">登录</a>
        </div>
    </div>
</body>
<include file="commonJs" />
<script>

    //点击提交
    $('#reg').click(function(){
        var tel      =$('#tel').val();
        var token    =$('#token').val();
        if(tel==''|| tel==null){
            fm.alert('请输入手机号');
            return false;
        }
        var myreg = /^1[34578]\d{9}$/;
        if(!myreg.test(tel))
        {
            fm.alert('请输入有效的手机号码！');
            return false;
        }
        if(token==''|| token==null){
            fm.alert('请输入验证码');
            return false;
        }
        var info = {};
        info.tel = tel;
        info.token = token;
        $.ajax({
            'url': "/base/Chargingdata/register",
            'data': info,
            'dataType':'json',
            'type': 'POST',
            success: function(data) {
                if (data.status == 'S'){
                    setTimeout("reload('"+data.url+"')", 2000);
                    fm.alert(data.message);
                }else{
                    fm.alert(data.message);
                    return false;
                }
            }
        })
    });

    var height=$(window).height();
    $('#register').css('minHeight',height);

    //点击获取验证码
    var verifyTag = true;
    $('.information-box').on('click', '.send', function (e) {
        e.preventDefault();
        var data={};
        data.tel  =$('#tel').val();
        if(data.tel==''|| data.tel==null){
            fm.alert('请输入手机号');
            return false;
        }
        var myreg = /^1[34578]\d{9}$/;
        if(!myreg.test(data.tel))
        {
            fm.alert('请输入有效的手机号码！');
            return false;
        }else{
            $.ajax({
                url:"/base/Chargingdata/sendText",
                type:"get",
                data:data,
                dataType:"json",
                success: function(msg){

                }
            });
        }
        if (verifyTag) timeCountDown(this);
        else return;
    });
    // 验证倒计时
    function timeCountDown(elem, seconds) {
        verifyTag = false;
        if (typeof seconds == undefined || seconds == null) seconds = 60;
        setTimeout(function () {
            if (seconds > 0) {
                seconds--;
                $(elem).text('已发送 ' + seconds + 's').addClass('time');
                timeCountDown(elem, seconds);
            } else {
                $(elem).removeClass('time').text('获取验证码');
                verifyTag = true;
            }
        }, 1000);
    }

    function reload(url) {
        location.href = url;
    }


</script>
</html>